<?php

/**
 * 附件上传
 */
namespace app\asset\controller;
use think\Controller;
class Asset extends Controller{


    function _initialize() {
    	$adminid=sp_get_current_admin_id();
    	$userid=sp_get_current_userid();
    	if(empty($adminid) && empty($userid)){
    		//exit("非法上传！");
    	}
    }
    public function preview(){

    }
    /**
     * swfupload 上传 
     */
    public function swfupload() {
		set_time_limit(0);
        header('Access-Control-Allow-Origin: *');
//        if (IS_POST) {
			
            //上传处理类
            $config=array(
            		'rootPath' => config("uploadimgpath"),
            		'savePath' => '',
            		'maxSize' => 18048576,
            		'saveName'   =>    array('uniqid',''),
            		'exts'       =>    array('jpg', 'gif', 'png', 'jpeg',"txt",'zip','apk','docx','doc','mp3','wav'),
            		'autoSub'    =>    false,
            );

			$upload = new \think\Upload($config);//
			$info=$upload->upload();
            //开始上传
            if ($info) {
                //上传成功
                //写入附件数据库信息
                $first=array_shift($info);
                if(!empty($first['url'])){
                	$url=$first['url'];
                }else{
                	$url=config("tmpl_parse_string.__UPLOAD__").$first['savename'];
                }
                
				//echo "1," . $url.",".'1,'.$first['name'];
                echo json_encode(array("status"=>1,"url"=>$url));
				exit;
            } else {
                //上传失败，返回错误
               // exit("0," . $upload->getError());
                echo json_encode(array("status"=>0,"url"=> $upload->getError()));
                exit;
            }
//        } else {
//            $this->display(':swfupload');
//        }
    }
    /**
     * 视频上传
     */
    public function videoupload() {
    	header('Access-Control-Allow-Origin: *');
    		
    	//上传处理类
    	$config=array(
    			'rootPath' => config("uploadvideopath"),
    			'savePath' => '',
    			'saveName'   =>    array('uniqid',''),
    			'exts'       =>    array('mp4', 'avi', 'wmv','rm','rmvb','mkv'),
    			'autoSub'    =>    false,
    	);
    	$upload = new \think\Upload($config);//
    	$info=$upload->upload();
    	//开始上传
    	if ($info) {
    	//上传成功
    	//写入附件数据库信息
    	$first=array_shift($info);
    	if(!empty($first['url'])){
    	$url=$first['url'];
    	}else{
    	$url=C("tmpl_parse_string.__UPLOAD__").$first['savename'];
    	}
    
    		//echo "1," . $url.",".'1,'.$first['name'];
    		echo json_encode(array("status"=>1,"url"=>$url));
    				exit;
    		} else {
    		//上传失败，返回错误
    		// exit("0," . $upload->getError());
    		echo json_encode(array("status"=>0,"url"=> $upload->getError()));
    		exit;
    	}
    	//        } else {
    	//            $this->display(':swfupload');
    		//        }
    	}
    	
}
